'''
数据库
'''
import sqlite3

class dbModel():
    def __init__(self):
        self.conn = sqlite3.connect("demo.db")
        self.cursor = self.conn.cursor()

    def tableAdd(self):
        sql = "create table news(id integer primary key autoincrement," \
              "title text,source text,rectime text)"
        self.cursor.execute(sql)
        self.conn.commit()

    def insertData(self,title,source,ctime):
        sql = "insert into news values(null,'{}','{}','{}')".format(title,source,ctime)
        print(sql)
        self.cursor.execute(sql)
        self.conn.commit()

    def queryData(self):
        sql = "select * from news"
        self.cursor.execute(sql)
        return self.cursor.fetchall()

if __name__=='__main__':
    from datetime import datetime
    d = dbModel()
    # d.tableAdd()
    cnow = datetime.now()
    d.insertData("天气很热","自己写的",cnow)
    print(d.queryData())
